<template>
	<view class="pages">
		<view class="form">
			<view class="inp">
				<text>抬头类型</text>
				<view class="">
					<u-radio-group v-model="form.lookUpType" :disabled="view"
					 style="justify-content: flex-end;">
						<u-radio v-for="(item, index) in list" :key="index" :name="item.value+''"
							:customStyle="{marginLeft: '30rpx',marginRight:'5rpx'}">
							{{ item.label }}
						</u-radio>
					</u-radio-group> 
				</view>
			</view> 
			<view class="inp">
				<text>发票抬头：</text>
				<view class="">
					<input v-model="form.invoiceName" type="text" :disabled="view"  placeholder="请输入"/>
					 
				</view>
			</view>
			<view class="inp" v-if="form.lookUpType==1">
				<text>发票税号 ：</text>
				<view class="">
					<input v-model="form.invoiceNumber" type="text"  :disabled="view" placeholder="请输入"/>
					 
				</view>
			</view>
			<view class="inp">
				<text>更多内容 ：</text>
				<view class="">
					<input v-model="form.remark" type="text" :disabled="view"  placeholder="选填"/>
					 
				</view>
			</view>
		</view>
		 
		<view class="form">
			<view class="inp" style="padding: 10rpx 0;">
				<text>发票金额</text>
				<view class="">
					<text>￥ </text>
					<text style="font-weight: 600;font-size: 40rpx;color: #333333;">{{form.money}}</text>
				 
				</view>

			</view>
		</view>
		<view style="font-weight: 400;font-size: 24rpx;color: #F93A59;margin-bottom: 20rpx">
			*开票金额不包含优惠券及积分兑换的抵扣额度
		</view>
		
		<view class="form">
			<view class="inp" style="padding: 10rpx 0;">
				<text>邮箱地址：</text>
				<view class="flex">
					<input type="text" v-model="form.email" placeholder="请输入您的邮箱地址" :disabled="view"/>
					<uni-icons  type="right" size="16"></uni-icons>
				</view>
		
			</view>
		</view> 
		
		<view class="footer" v-if="!view">
			<view class="btn" @click="up">
				申请电子发票
			</view>
		</view>
	</view>
</template>

<script>
	import { getDictDataAPI} from "@/api/api.js"
	import {createinvoiceAPI,getinvoiceAPI} from "@/api/user.js"
 	 
	import {orderdetailAPI} from "@/api/order.js" 
	export default {
		components:{
			 
		},
		data() {
			return {
				form: {
					remark:"",
					lookUpType:"1",
					money:0,
					email:""
				},
				list:[ ],
				 
				view:false, 
				id: "",
				show:false
			}
		},
		
		onLoad(option) {
			if(option.view=="true"){
				this.view=true
				getinvoiceAPI({orderId:this.form.orderId}).then(res=>{
					this.form=res
					this.form.lookUpType=res.lookUpType+''
				})
			}
			this.form.orderId=option.id
			this.getdata()
			 
		},
		methods: {
			getdata() {
				getDictDataAPI("look_up_type").then(res => {
					this.list = res
				})
				orderdetailAPI({id:this.form.orderId}).then(res=>{
					this.form.money=res.actualMoney
				})
				
			},
			 
			up() {
				console.log(this.form)
				createinvoiceAPI(this.form).then(res => {
					uni.showToast({
						title: '提交成功'					 
					})
					let pages = getCurrentPages(); // 当前页面
					let beforePage = pages[pages.length - 2];
					setTimeout(()=>{
						uni.navigateBack({
							success() {
								beforePage.$vm.resetQuery();
							}
						})
					},1000)
				}) 
			}, 
		 }
	}
</script>

<style lang="scss" scoped>
	.pages {
		padding: 30rpx;
		background-color: #F7F8FA;
		min-height: 100vh;
	}

	.avatar {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		background-color: #efefef;

		padding: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		image {
			width: 80px;
			height: 80rpx;
			border-radius: 50%;
		}

		text {
			color: #666;
			font-size: 20rpx;
		}
	}

	.form {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		margin-top: 20rpx;

		.inp {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			>text {
				font-weight: 600;
				font-size: 32rpx;
				color: #333333;
				// width: 190rpx;
			}

			view {

				image {
					width: 40rpx;
					height: 40rpx;
					margin: 0 10rpx;
				}

				input {
					text-align: right;
				}
			}

		}
	}


 
</style>